package com.byt.xmxb.viewmodel;

import com.byt.base.activity.IBaseView;
import com.byt.base.model.BaseModel;
import com.byt.base.utils.Utils;
import com.byt.base.viewmodel.BaseViewModel;
import com.byt.common.view.finder.entity.Province;
import com.byt.xmxb.model.ProvinceModel;

import java.util.ArrayList;

public class ProvinceViewModel extends BaseViewModel<ProvinceViewModel.ProvinceView, ProvinceModel>
        implements BaseModel.IModelListener<ArrayList<Province>> {
    
    public ProvinceViewModel() {
        model = new ProvinceModel();
        // 注册监听
        model.register(this);
        // 请求加载数据
        model.getCachedDataAndLoad();
    }

    @Override
    public void onLoadFinish(BaseModel model, ArrayList<Province> data) {
        if (getPageView() != null) {
            if (model instanceof ProvinceModel) {
                if (Utils.isEmpty(data)) {
                    getPageView().showEmpty();
                } else {
                    getPageView().getAreList(data);
                }
            }
        }
    }

    @Override
    public void onLoadFail(BaseModel model, String msg) {
        if (getPageView() != null) {
            getPageView().onRefreshFailure(msg);
        }
    }


    public interface ProvinceView extends IBaseView {
        void getAreList(ArrayList<Province> arrayList);
    }

}
